package com.example.doer.reading.AppDataModel;

import android.content.Context;

import com.ab.http.AbHttpUtil;
import com.ab.http.AbStringHttpResponseListener;
import com.example.doer.reading.global.MyApplication;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;

/**
 * Created by doer on 2017/7/14.
 */
public class AppUser implements Serializable{
    private String UserID;
    private String UserName;
    private String UserDescription;
    private String UserPassWord;
    private String UserLogoPath;
    private String UserSex;
    private String UserCity;
    private String UserJob;
    private String UserSchool;

    private String CreateTime;
    private int UserRights;
    private String AccessToken;
    private boolean isLoginUser;
    public String getUserID() {
        return UserID;
    }

    public void setUserID(String userID) {
        UserID = userID;
    }

    public String getUserName() {
        return UserName;
    }

    public void setUserName(String userName) {
        UserName = userName;
    }

    public String getUserDescription() {
        return UserDescription;
    }

    public void setUserDescription(String userDescription) {
        UserDescription = userDescription;
    }

    public String getUserPassWord() {
        return UserPassWord;
    }

    public void setUserPassWord(String userPassWord) {
        UserPassWord = userPassWord;
    }

    public String getUserLogoPath() {
        return UserLogoPath;
    }

    public void setUserLogoPath(String userLogoPath) {
        UserLogoPath = userLogoPath;
    }

    public String getUserSex() {
        return UserSex;
    }

    public void setUserSex(String userSex) {
        UserSex = userSex;
    }

    public String getUserCity() {
        return UserCity;
    }

    public void setUserCity(String userCity) {
        UserCity = userCity;
    }

    public String getUserJob() {
        return UserJob;
    }

    public void setUserJob(String userJob) {
        UserJob = userJob;
    }

    public String getUserSchool() {
        return UserSchool;
    }

    public void setUserSchool(String userSchool) {
        UserSchool = userSchool;
    }

    public String getCreateTime() {
        return CreateTime;
    }

    public void setCreateTime(String createTime) {
        CreateTime = createTime;
    }

    public int getUserRights() {
        return UserRights;
    }

    public void setUserRights(int userRights) {
        UserRights = userRights;
    }

    public String getAccessToken() {
        return AccessToken;
    }

    public void setAccessToken(String accessToken) {
        AccessToken = accessToken;
    }

    public boolean isLoginUser() {
        return isLoginUser;
    }

    public void setLoginUser(boolean loginUser) {
        isLoginUser = loginUser;
    }

    public static void getUserFromServer(Context context){
        String url="http://192.168.191.1/Reading/InfoDoServlet?Action=down&UserID="+MyApplication.user.getUserID();
        final AbHttpUtil abHttpUtil=AbHttpUtil.getInstance(context);
        abHttpUtil.get(url, new AbStringHttpResponseListener() {
            @Override
            public void onSuccess(int i, String s) {
                try {
                    JSONObject jsonObject=new JSONObject(s);
                    JSONObject object=jsonObject.getJSONObject("user");
                    MyApplication.user.setUserName(object.getString("userName"));
                    MyApplication.user.setUserSex(object.getString("userSex"));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onStart() {

            }

            @Override
            public void onFinish() {

            }

            @Override
            public void onFailure(int i, String s, Throwable throwable) {

            }
        });
    }


}
